import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { formatToYuan } from '#/utils/common';
import { renderDictTag } from '#/utils/render';

/**
 * 订单状态选项
 */
export const orderStatusOptions = [
  {
    dictLabel: '待支付',
    dictValue: 1,
    listClass: 'orange',
    label: '待支付',
    value: 1,
  },
  {
    dictLabel: '预约中',
    dictValue: 2,
    listClass: 'blue',
    label: '预约中',
    value: 2,
  },
  {
    dictLabel: '预约成功',
    dictValue: 3,
    listClass: 'green',
    label: '预约成功',
    value: 3,
  },
  {
    dictLabel: '预约失败',
    dictValue: 4,
    listClass: 'red',
    label: '预约失败',
    value: 4,
  },
  {
    dictLabel: '已退款',
    dictValue: 5,
    listClass: 'purple',
    label: '已退款',
    value: 5,
  },
  {
    dictLabel: '已取消',
    dictValue: 6,
    listClass: 'gray',
    label: '已取消',
    value: 6,
  },
];

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    componentProps: {
      options: orderStatusOptions,
    },
    fieldName: 'orderStatus',
    label: '订单状态',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    title: '订单号',
    field: 'orderNo',
    width: 250,
  },
  {
    title: '医院名称',
    field: 'hospitalName',
    width: 150,
  },
  // {
  //   title: '科室名称',
  //   field: 'departmentName',
  //   width: 120,
  // },
  {
    title: '医生名称',
    field: 'doctorName',
    width: 100,
  },
  {
    title: '病历人',
    field: 'userName',
    width: 100,
  },
  {
    title: '联系电话',
    field: 'mobile',
    width: 120,
  },
  {
    title: '预约项目',
    field: 'reservationUserName',
    width: 100,
    slots: {
      default: ({ row }) => {
        return row.orderItemDtoList[0].projectName;
      },
    },
  },
  {
    align: 'right',
    title: '订单价格',
    field: 'orderPrice',
    width: 100,
    formatter: ({ cellValue }) => {
      return formatToYuan(cellValue);
    },
  },
  {
    title: '预约时间',
    field: 'reservationTimeStr',
    width: 180,
  },
  {
    title: '症状描述',
    field: 'medicalRemark',
    minWidth: 200,
  },
  {
    title: '订单状态',
    field: 'orderStatus',
    width: 100,
    slots: {
      default: ({ row }) => {
        return row.orderStatus !== null && row.orderStatus !== undefined
          ? renderDictTag(row.orderStatus, orderStatusOptions)
          : '';
      },
    },
  },
  {
    title: '创建时间',
    field: 'gmtCreated',
    width: 160,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

/**
 * 预约状态选项（仅用于修改状态）
 */
export const reservationStatusOptions = [
  {
    label: '预约成功',
    value: 1,
  },
  {
    label: '预约失败',
    value: 2,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    componentProps: {
      allowClear: true,
      options: reservationStatusOptions,
    },
    fieldName: 'type',
    label: '预约状态',
    rules: 'selectRequired',
  },
];
